<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /*
            本节核心内容: Object.defineProperties(obj3,Object.getOwnPropertyDescriptors(obj));可以将obj完全复制给obj3

            Object.getOwnPropertyDescriptors(obj)
                - 返回obj对象中每个属性的value、enumerable、writable、configurable等属性值
                - 返回形式是:{
                    key1:{
                        value:'xxx',
                        enumerable:boolean,
                        writable:boolean,
                        ...
                    },
                    key2:{},
                    ...
                }
                - 主要用途在于对象的复制，Object.assign()无法将原对象中的get、set等控制的属性里的细节复制过来，他只能把这个属性以及当时的值复制过来。说起来有点抽象，你看看下面的演示就懂了
        */ 
        let obj = {
            name:'mikaisa',
            age:18,
            location:{
                city:'苏州',
                province:'江苏'
            },
            //比如这里的city属性是通过get和set和locaiton.city联动起来的, Object.assign()是没法把这些联动复制的
            get city(){
                console.log('有人读取city属性');
                return this.location.city;
            },
            set city(data){
                console.log('有人赋值city属性');
                this.location.city = data;
            }
        }
        let obj2 = {};
        Object.assign(obj2,obj);
        console.log(obj2);//你会发现obj2的city直接是'苏州',后续修改不会再与location.city有任何联动
        let obj3 = {};
        Object.defineProperties(obj3,Object.getOwnPropertyDescriptors(obj));//这样就实现了完全的复制
        console.log(obj3);
    </script>
</body>
</html>